name: Speed benchmarks

on:
  schedule:
    - cron: '0 23 * * SUN-THU'

jobs:
  speed-benchmarks:
    runs-on: ubuntu-latest

    # Not intended for forks.
    if: github.repository == 'optuna/optuna'

    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Setup Python3.11
      uses: actions/setup-python@v5
      with:
        python-version: 3.11

    - name: Setup cache
      uses: actions/cache@v3
      env:
        cache-name: speed-benchmarks
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-3.11-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1
        restore-keys: |
          ${{ runner.os }}-3.11-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}

    - name: Install
      run: |
        python -m pip install --upgrade pip
        pip install --progress-bar off -U setuptools

        # Install minimal dependencies and confirm that `import optuna` is successful.
        pip install --progress-bar off .
        python -c 'import optuna'
        optuna --version

        pip install --progress-bar off .[benchmark] --extra-index-url https://download.pytorch.org/whl/cpu
        asv machine --yes

    - name: Output installed packages
      run: |
        pip freeze --all
    - name: Output dependency tree
      run: |
        pip install pipdeptree
        pipdeptree

    - name: Speed benchmarks
      run: |
        asv run
